package cn.kgc.search.utils;

import cn.kgc.common.entity.Article;
import cn.kgc.search.entity.ESArticle;
import cn.kgc.search.entity.ESCategory;

import java.time.LocalDate;
import java.time.ZoneId;

/**
 * Created by teacher ZHANG on 2023/2/13
 */
public class ArticleUtil {
    public static ESArticle convert(Article article) {
        ESArticle esArticle = new ESArticle();
        esArticle.setArticleId(article.getArticleId());
        esArticle.setTitle(article.getTitle());
        esArticle.setContent(article.getContent());
        esArticle.setImage(article.getImage());

        LocalDate date = article.getCreateDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        esArticle.setCreateDate(date);

        ESCategory esCategory = new ESCategory();
        esCategory.setCategoryId(article.getCategory().getCategoryId());
        esCategory.setCategoryName(article.getCategory().getCategoryName());

        esArticle.setCategory(esCategory);

        return esArticle;
    }
}
